package com.shsh.safemanage.util;

import javax.servlet.http.HttpServletRequest;

public class RequestUtil {

	public static Integer getParameter(HttpServletRequest request, String parameterName, Integer defaultValue) {
		try {
			return Integer.parseInt(request.getParameter(parameterName));
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static Long getParameter(HttpServletRequest request, String parameterName, Long defaultValue) {
		try {
			return Long.parseLong(request.getParameter(parameterName));
		} catch (Exception e) {
			return defaultValue;
		}
	}

	public static Boolean getParameter(HttpServletRequest request, String paramterName, Boolean defaultValue) {
		try {
			String param = request.getParameter(paramterName);
			if (param == null || param.equalsIgnoreCase("null")) {
				return defaultValue;
			}
			return Boolean.parseBoolean(param);
		} catch (Exception e) {
			return defaultValue;
		}
	}
}
